package com.huawei.appmarket.framework.activity;

import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
import android.os.Message;
import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;
import java.util.ArrayList;
import o.cjl;
import o.cks;
import o.cku;
import o.doo;
import o.ContentManager;
import o.dvr;
import o.dvt;
import o.dvw;
import o.dwh;
import o.epj;
import o.epw;
import o.NetWorkUtil;
import o.ewg;
import o.ewm.i;
import o.ewm.n;
import o.ll;

public class DownloadPauseDialog extends SafeBroadcastReceiver {
    protected static final DownloadPauseDialog DIALOG = new DownloadPauseDialog();
    public static final String DIALOG_POPUP_BROADCAST = (ContentManager.getInstant().getContext().getPackageName() + ".dialogpopupreceiver");
    public static final String DIALOG_POPUP_DOWNBROADCAST = (ContentManager.getInstant().getContext().getPackageName() + ".dialogpopdownreceiver");
    public static final String DOWNLOADED_APK_PATH = "DownloadedApkPath";
    public static final String DOWNLOADED_APP_NAME = "DownloadedAppName";
    public static final String DOWNLOADED_PACKAGENAME = "DownloadedPackageName";
    public static final String DOWNLOAD_HTTPS_DIALOG_NAME = "HttpsDownloadDialog";
    public static final String PENDING_NUMBER = "pending.number";
    public static final String PENDING_TASK = "pending.task";
    public static final String REDOWNLOAD_TASK = "redownload.task";
    private static Context ˎ = null;
    private final Handler ˊ = new Handler(this) {
        final /* synthetic */ DownloadPauseDialog ˏ;

        {
            this.ˏ = r1;
        }

        public void handleMessage(Message message) {
            if (1 == message.what) {
                a aVar = (a) message.obj;
                this.ˏ.ˊ(aVar.ˋ, aVar.ॱ);
            }
        }
    };

    static class a {
        public Context ˋ;
        public Intent ॱ;

        private a() {
        }
    }

    static class b implements cks {
        private b() {
        }

        public void enableNetworking() {
            dvt.ˏ().ˎ(2, new e());
        }

        public void upgrade() {
        }

        public void ˋ() {
        }
    }

    static class e implements dwh {
        private e() {
        }

        public void ˏ(SessionDownloadTask sessionDownloadTask) {
            sessionDownloadTask.ˏ(doo.ʻ(ContentManager.getInstant().getContext()));
        }
    }

    public static DownloadPauseDialog register(Context context) {
        IntentFilter intentFilter = new IntentFilter(DIALOG_POPUP_BROADCAST);
        intentFilter.addAction(DIALOG_POPUP_DOWNBROADCAST);
        intentFilter.addAction(dvw.ॱ);
        ll.ˏ(context).ˏ(DIALOG, intentFilter);
        ˎ = context;
        return DIALOG;
    }

    public static void unRegister(Context context) {
        if (context != null) {
            ll.ˏ(context).ˋ(DIALOG);
            ˎ = null;
        }
    }

    private synchronized void ˊ(Context context, Intent intent) {
        CharSequence charSequence = null;
        synchronized (this) {
            int intExtra = intent.getIntExtra(PENDING_NUMBER, 0);
            if (intExtra > 0) {
                if (!(dvr.ˏ(context, true) || cku.ˏ(context, "DownloadPauseDialog"))) {
                    CharSequence quantityString = context.getResources().getQuantityString(i.ॱ, intExtra, new Object[]{Integer.valueOf(intExtra)});
                    if (doo.ʻ(context)) {
                        charSequence = epw.ॱ(context, n.ʽ, new Object[0]);
                    } else if (doo.ॱॱ(context) && doo.ᐝ(context)) {
                        charSequence = NetWorkUtil.rebuildWifiKey(epw.ॱ(context, n.ʻ, new Object[0]));
                    }
                    cku ˏ = cku.ˏ(ˎ, cku.class, quantityString, charSequence);
                    ˏ.ॱ(new b());
                    ˏ.ॱ(-2, context.getResources().getString(n.ʼ));
                    ˏ.ॱ(-1, context.getResources().getString(n.ᐝ));
                    ˏ.ˋ(ˎ, "DownloadPauseDialog");
                }
            }
        }
    }

    private synchronized void ˎ() {
        if (DIALOG != null) {
            cku.ˎ(ˎ, "DownloadPauseDialog");
        }
    }

    private void ˋ(Intent intent) {
        epj o_epj = new epj();
        Context ˋ = ContentManager.getInstant().getContext();
        o_epj.ˋ(ˋ.getString(n.ʻʾ));
        o_epj.ˏ(ˋ.getString(n.ʹˋ));
        o_epj.ॱ(ˋ.getString(n.ʻˈ));
        o_epj.ˎ(ˋ.getString(n.ﾟᐝ));
        ewg.ॱ(ˎ, o_epj, cjl.ˋ("installmgr.activity"), true, "NoSpaceDialog");
    }

    private void ˏ(Context context, long j, ArrayList<String> arrayList, long j2) {
        ewg.ˊ(ˎ, context.getString(n.ʻʾ), context.getString(n.ʴॱ), j, arrayList, j2).ˋ(ˎ, "NoSpaceToCancelTask" + System.currentTimeMillis());
    }

    public void onReceiveMsg(Context context, Intent intent) {
        if (intent == null) {
            return;
        }
        if (dvw.ॱ.equals(intent.getAction())) {
            ArrayList stringArrayListExtra = intent.getStringArrayListExtra("CANCEL_PKGS");
            if (stringArrayListExtra == null || stringArrayListExtra.size() <= 0) {
                ˋ(intent);
                return;
            }
            ˏ(context, intent.getLongExtra("APP_PKG", 0), stringArrayListExtra, intent.getLongExtra("CLEAR_SPACE", 0));
        } else if (DIALOG_POPUP_BROADCAST.equals(intent.getAction())) {
            showDialog(1, context, intent);
        } else if (DIALOG_POPUP_DOWNBROADCAST.equals(intent.getAction())) {
            ˎ();
        }
    }

    public void showDialog(int i, Context context, Intent intent) {
        if (!this.ˊ.hasMessages(i)) {
            a aVar = new a();
            aVar.ˋ = context;
            aVar.ॱ = intent;
            Message obtainMessage = this.ˊ.obtainMessage();
            obtainMessage.what = i;
            obtainMessage.obj = aVar;
            this.ˊ.sendMessage(obtainMessage);
        }
    }
}
